const app = getApp()
Page({
  data: {
    category: [{name:'壁画',id:1},{name:'装裱字画',id:2},],
    curIndex: 0,
    products: [1,2]
  },
  onReady() {
    var self = this;
    let serverUrl = app.globalData.serverUrl + '/getCategoryList';
    wx.request({
      url: serverUrl,
      success(res) {
        self.setData({
          category: res.data.data
        })
      }
    });

  },
  switchTab(e) {
    var cid = e.target.dataset.id;
    const self = this;
    let serverUrl = app.globalData.serverUrl + 'getProductByCategoryId?from=0&to=2&cid=' + cid;
    wx.request({
      url: serverUrl,
      success(res) {
        var p = [];
        for (var item of res.data.data) {
          p.push(item.name);
        }
        self.setData({
          curIndex: e.target.dataset.index,
          products: p
        })
      }
    })

  }

})